<template>
    <div>
        <div class="container" style="border-top: 1px solid #E6E6E6;width: 1500px;">
            <div class="user-index">
                <div class="user-index-header">
                    <div class="user-index-header-title">
                    </div>
                </div>
                <div class="user-index-body">
                    <div class="user-index-body-form">
                        <el-form ref="from"
                            style="max-width: 100%; display: flex; flex-wrap: wrap; gap: 20px;margin-top: 20px;"
                            :model="formData" label-width="auto" class="demo-ruleForm" status-icon>

                            <el-form-item label="客户：" prop="name" style="margin-right: 60px; margin-left: 50px;">
                                <span>{{ formData.erpSupplier.supName }}</span>
                            </el-form-item>

                            <el-form-item label="单据日期：" prop="date" style="margin-right: 60px;">
                                <span>{{ formData.createTime }}</span>
                            </el-form-item>

                            <el-form-item label="单据编号：" prop="number" style="margin-right: 60px;">
                                <span>{{ formData.number }}</span>
                            </el-form-item>



                            <div class="user-index-body-form-btn">
                                <div class="user-index-body-form-btn-item">


                                    <el-table :data="records" border style="width: 1500px;margin-bottom: 20px;">
                                        <el-table-column v-if="showIdColumn" prop="mid"  />
                                        <el-table-column v-if="showIdColumn" prop="aid"  />

                                        <el-table-column prop="barCode" label="条码" />
                                        <el-table-column prop="materialName" label="名称" />
                                        <el-table-column prop="standard" label="规格" />
                                        <el-table-column prop="model" label="型号" />
                                        <el-table-column prop="color" label="颜色" />


                                        <el-table-column prop="mfrs" label="扩展信息" />
                                        <el-table-column prop="unit" label="库存" />
                                        <el-table-column prop="commodityUnit" label="单位" />
                                        <el-table-column prop="sku" label="多属性" />
                                        <el-table-column prop="operNumber" label="数量" />
                                        <el-table-column prop="unitPrice" label="单价" />
                                        <el-table-column prop="allPrice" label="金额" />
                                        <el-table-column prop="taxRate" label="税率(%)" />
                                        <el-table-column prop="taxMoney" label="税额" />
                                        <el-table-column prop="taxLastMoney" label="价税合计" />
                                        <el-table-column prop="remark" label="备注" />


                                    </el-table>
                                </div>
                            </div>

                            <div class="index-body tb">
                                <el-form-item label="优惠率：" style="margin-right: 120px;">
                                    <span>0%</span>
                                </el-form-item>
                                <el-form-item label="收款优惠：" style="margin-right: 120px;">
                                    <span>0</span>
                                </el-form-item>
                                <el-form-item label="优惠后金额：">
                                    <span>{{ formData.totalPrice }}</span>
                                </el-form-item>

                            </div>

                            <div class="index-body zb">
                                <el-form-item label="结算账户：" style="margin-right: 120px;">
                                    <span>{{records.name}}</span>
                                </el-form-item>
                                <el-form-item label="收取定金：" style="margin-right: 100px;">
                                    <span></span> </el-form-item>
                            </div>



                            <div class="index-body wb" style="margin-top: 100px;margin-left: 1250px;">
                                <div class="ant-coloery" style="margin-right: 10px;">
                                    <el-button :disabled="true">取消</el-button>
                                </div>
                                <div class="ant-coloery" style="margin-right: 10px;">
                                    <el-button :disabled="true">保存并审核</el-button>
                                </div>
                                <div class="ant-coloery" style="margin-right: 10px;">
                                    <el-button type="primary" :disabled="true">保存</el-button>
                                </div>
                            </div>

                        </el-form>
                    </div>
                </div>
            </div>
        </div>
        <el-dialog :destroy-on-close="true" :title="title" v-model="visible" width="65%"
            style="margin-left: 350px;margin-top: 200px">
            <router-view @close="close" :data="data"></router-view>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup>
import { reactive, ref, onMounted } from 'vue';
import type { FormInstance } from 'element-plus';
import router from '@/router';
import request from '@/api/request';

const visible = ref(false);
const title = ref("");
const data = ref({});

// 定义表单数据结构
interface RuleForm {
    name: string;
    date: string;
    location: string;
    number: string;
}
const insert = (p) => {
    title.value = p.cname;
    visible.value = true;
    router.push(p.path);
};

// 表单引用
const ruleFormRef = ref<FormInstance>();
// 表单数据
const ruleForm = reactive<RuleForm>({
    name: '',
    date: '',
    number: '', // 开始时为空，将在 onMounted 中设置
    location: ''
});

const close = () => {
    visible.value = false;
};



// 表格数据，需包含条码、名称、规格等字段
const tableData = [
    { barcode: '123456789', name: '商品名称', specification: '规格信息', stock: 10, unit: '件', quantity: 5, price: 100.00, amount: 500.00, taxRate: '10%', tax: 50.00, total: 550.00, remark: '无' },
    { barcode: '987654321', name: '商品名称2', specification: '规格信息2', stock: 20, unit: '件', quantity: 10, price: 150.00, amount: 1500.00, taxRate: '15%', tax: 225.00, total: 1725.00, remark: '备注信息' },
];

// 提交表单
const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return;
    await formEl.validate((valid, fields) => {
        if (valid) {
            console.log('提交成功！');
        } else {
            console.log('提交错误！', fields);
        }
    });
}

// 重置表单
const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return;
    formEl.resetFields();
};
let props = defineProps(["data"])
let emits = defineEmits(["close"])
let formData = ref({ ...props.data })
console.log(formData.value);
const records=ref([])

const loadData = () => {
    request({
        url: '/erpmaterialinventory/listxq',
        method: "get",
        params: {
            headerId: formData.value.id
        }
    }).then(res => {
        console.log(res);
        records.value = res.data



    })
}

loadData();
</script>

<style></style>